<meta charset="utf-8">
<link href="../westcss/bootstrap.min.css" rel="stylesheet" type="text/css" />
<style>
li{list-style:none;display:inline;}
</style>
<div class="modal fade" id="demoModal" tabindex="-1" role="dialog" aria-labelledby="demoModalLabel" aria-hidden="true" data-backdrop="static">
		<div class="modal-dialog" style="width: 500px;">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="demoModalLabel">资产列表</h4>
				</div>
				<div class="modal-body" style="height: 300px;">
					<div id="zcdetailId"></div>
				</div><!-- /.modal-body -->
				
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
</div>
					
<div id="mainbackup" style="width:100%;height:100%"></div>
<script src="../westjs/echarts.min.js"></script>
<script src="../westjs/world.js"></script>
<script src="../westjs/jquery.min.js"></script>
<script src="../westjs/bootstrap.min.js" type="text/javascript"></script>
<script src="../westjs/jquery-ui-custom.min.js"></script>
<!--添加全局申请ip-->
    <script src="../gobal_ip/gobal_ip.js" type="text/javascript"></script>
<script>
$.ajaxSetup({
	async: false
});
//@模态框
function modalInit(modalName)
{
	var modalName = '#' + modalName;
	//设置模态框可移动
	$(modalName).draggable({   
		handle: ".modal-header",   
		cursor: 'move',   
		refreshPositions: false
	});
			
	//模态框居中显示
	function centerModals() {   
		$(modalName).each(function(i){  
			var $clone = $(this).clone().css('display', 'block').appendTo('body');
			//设置modal垂直居中
			var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);   
			top = top > 0 ? top : 0;   
			$(this).find('.modal-content').css("margin-top", top);
			$clone.remove();
		   
		});
	}
	//调用show方法时触发
	$(modalName).on('show.bs.modal', function(){
		centerModals();
		
	});
	$(window).on('resize', centerModals);  
}
function modalInit_maptip(modalName)
{
	var modalName = '#' + modalName;
	//设置模态框可移动
	$(modalName).draggable({   
		handle: ".modal-header",   
		cursor: 'move',   
		refreshPositions: false
	});
			
	//模态框居中显示
	function centerModals() {   
		$(modalName).each(function(i){  
			var $clone = $(this).clone().css('display', 'block').appendTo('body');
			//设置modal垂直居中
			var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);   
			top = top > 0 ? top : 0;   
			$(this).find('.modal-content').css("margin-top", top);
			$clone.remove();
		   
		});
	}
	//调用show方法时触发
	$(modalName).on('show.bs.modal', function(){
		centerModals();
	});
	$(window).on('resize', centerModals);  
}
	
function switchStrToNum(arrStr)
{
	var arr=[]
	for(var i=0;i<arrStr.length;i++)
	{
		arr[i]=parseFloat(arrStr[i]);
	}
	return arr;
}

var dataCenterArr=[];
var dataCenter=[];
$.get(encodeURI("http://"+global_ip+"/networkassetinfocon/getallorganization"),function(data){
	$(data.data).each(function(index,item){
		dataCenterArr.push(
			{
			zzjg:item.zzjg,
			zcwz:switchStrToNum(item.zcwz.split(","))
			}
		);
		dataCenter.push(
			{
			zzjg:item.zzjg,
			zcwz:item.zcwz
			}
		);
	})
});
//console.log(dataCenterArr[0].zcwz);
var myChartBackup = echarts.init(document.getElementById('mainbackup'));
//@ little bug
var geoCoordMap1 = {		
	"信息中心-网络安全管理中心":dataCenterArr[0].zcwz,		
	'伦敦': [-0.127758,51.507351]
};
var GZData1 = [
	[{name:'伦敦'},{name:dataCenterArr[0].zzjg,value:180}]
];

var convertData1 = function (data) {
	var res = [];
	for (var i = 0; i < data.length; i++) {
		var dataItem = data[i];
		var fromCoord = geoCoordMap1[dataItem[0].name];
		var toCoord = geoCoordMap1[dataItem[1].name];
		if (fromCoord && toCoord) {
			res.push({
				fromName: dataItem[0].name,
				toName: dataItem[1].name,
				coords: [fromCoord, toCoord]
			});
		}
	}
	return res;
};

var series = [];
[['伦敦', GZData1]].forEach(function (item, i) {
	//console.log(convertData1(item[1]));
	series.push(
	{
		type: 'lines',
		zlevel: 1,
		effect: {
			show: true,
			period: 6,
			trailLength: 0.9,
			color: 'blue',
			symbolSize: 5
		},
		lineStyle: {
			normal: {
				color: "red",
				width: 0,
				curveness: 0.2
			}
		},
		data: convertData1(item[1])
	},
	{
		type: 'lines',
		zlevel: 2,
		effect: {
			show: true,
			period: 6,
			trailLength: 0
			
		},
		lineStyle: {
			normal: {
				color: "red",
				width: 1,
				opacity: 0.7,
				curveness: 0.2
			}
		},
		data: convertData1(item[1])
	},
	{
		type: 'effectScatter',
		coordinateSystem: 'geo',
		zlevel: 2,
		rippleEffect: {
			brushType: 'stroke'
		},
		label: {
			normal: {
				show: true,
				position: 'right',
				formatter: '{b}'
			}
		},
		symbol:'circle',
		symbolSize: function (val) {
			return val[2] / 8;
		},
		itemStyle: {
			normal: {
				color: "#BF0060"
			}
		},
		data: item[1].map(function (dataItem) {
			return {
				name: dataItem[1].name,
				value: geoCoordMap1[dataItem[1].name].concat([dataItem[1].value])
			};
		})
	});
	
});

var option = {
	backgroundColor: '#fff',
   
	geo: {
		map: 'world',
		label: {
			emphasis: {
				show: false
			}
		},
		zoom:1.25,
		roam: true,
		itemStyle: {
			normal: {
				areaColor: '#fff',
				borderColor: '#111'
			},
			emphasis: {
				areaColor: 'blue'
			}
		}
	},
	series : series
};
myChartBackup.setOption(option);

function getzcType(arr)
{
	var res=[];
	var resNew=[];
	
	for(var i=0;i<arr.length;i++)
	{
		res[i]=arr[i].zclx;
	}
	
	res.sort(); 
	var resNew=[res[0]]; 
	for(var i = 1; i < res.length; i++){ 
		if( res[i] !== resNew[resNew.length-1]){ 
			resNew.push(res[i]); 
		} 
	} 
	return resNew; 
}

function getzcdetailByType(typeStr,dealArr)
{
	var res=[];
	var k=0;
	for(var i=0;i<dealArr.length;i++)
	{
		if(dealArr[i].zclx==typeStr)
		{
			res[k]=dealArr[i];
			k++;
		}
	}
	return res;
}

//@跳转到资产详情页
function gotoZcpageByzcbh(zcid)
{
	window.open('../ljw/zcxq.html?id='+zcid);
}

myChartBackup.on('mouseover', function (params) {
    // 控制台打印数据的名称
    if(params.name==dataCenterArr[0].zzjg)
	{
		$("#zcdetailId").empty();
		var zcdetail=[];
		var jsonmapObj={zzjg:dataCenter[0].zzjg,zcwz:dataCenter[0].zcwz};
		$.get(encodeURI("http://"+global_ip+"/networkassetinfocon/getassetlist?param="+JSON.stringify(jsonmapObj)),function(data){
			$(data.data).each(function(index,item){
				//console.log(item);
				zcdetail.push({
					id:item.id,
					zcbh:item.zcbh,
					zclx:item.zclx,
					zcmc:item.zcmc
				})
			})
		});
		//console.log(getzcType(zcdetail));
		var zclxArr=getzcType(zcdetail);
		console.log(getzcdetailByType(zclxArr[0],zcdetail));
		for(var i=0;i<zclxArr.length;i++)
		{
			$("#zcdetailId").append("<ul id='"+i+"'>"+zclxArr[i]+":"+"&nbsp</ul><br>");
			var zcdetailtmp=getzcdetailByType(zclxArr[i],zcdetail);
			for(var j=0;j<zcdetailtmp.length;j++)
			{
				$("#"+i).append("<li><a href='#' onclick="+"gotoZcpageByzcbh('"+zcdetailtmp[j].id+"')>"+zcdetailtmp[j].zcmc+"</a><li>"+"&nbsp");
			}
			
		}
		modalInit("demoModal");
		$("#demoModal").modal('show');
		
	}
		
});

</script>
